Skip to content

Conversation

0xrusowsky
Copy link
Contributor

@0xrusowsky 0xrusowsky commented Jul 2, 2025

Motivation

Rewrite forge-fmt entirely to use Solar as the Solidity/Yul parser and AST, and using a structured pretty-printing algorithm.

The language-agnostic implementation of the pretty-printer (src/pp) is based on rustc_ast_pretty and prettyplease, both MIT and Apache licensed. See prettyplease's README for algorithm notes.

The goal of this PR is to make progress with #9317, and fixing existing issues with the formatter while trying to maintain compatibility as much as possible.

This PR will not be replacing the formatter yet, opting to create a separate crate crates/fmt-2 to reduce unrelated changes and aid with review. A follow-up PR will replace crates/fmt and deal with fallout in-tree.

Issues

Issues that will be fixed with the new implementation. Not closed by this PR, but by the follow-up that will hook the new implementation up; see paragraph above.

Tests state

  • ArrayExpressions
  • BlockComments
  • BlockCommentsFunction
  • ConditionalOperatorExpression
  • ConstructorDefinition
  • ConstructorModifierStyle
  • ContractDefinition
  • DocComments
  • DoWhileStatement
  • EmitStatement
  • EnumDefinition
  • EnumVariants
  • ErrorDefinition
  • EventDefinition
  • ForStatement
  • FunctionCall
  • FunctionCallArgsStatement
  • FunctionDefinition
  • FunctionDefinitionWithFunctionReturns
  • FunctionType
  • HexUnderscore
  • IfStatement
  • IfStatement2
  • ImportDirective
  • InlineDisable
  • IntTypes
  • LiteralExpression
  • MappingType
  • ModifierDefinition
  • NamedFunctionCallExpression
  • NumberLiteralUnderscore
  • OperatorExpressions
  • PragmaDirective
  • Repros
  • ReturnStatement
  • RevertNamedArgsStatement
  • RevertStatement
  • SimpleComments
  • SortedImports
  • StatementBlock
  • StructDefinition
  • ThisExpression
  • TrailingComma
    • NOTE: solar error
  • TryStatement
  • TypeDefinition
  • UnitExpression
  • UsingDirective
  • VariableAssignment
  • VariableDefinition
  • WhileStatement
  • Yul
    • STYLE: pending review
  • YulStrings

Supported Configs:

  • indent_style = IndentStyle
  • multiline_func_header: MultilineFuncHeaderStyle
  • line_length: usize
  • tab_width: usize
  • bracket_spacing: bool
  • int_types: IntTypes
  • quote_style: QuoteStyle
  • number_underscore: NumberUnderscore
  • hex_underscore: HexUnderscore
  • single_line_statement_blocks: SingleLineBlockStyle
  • override_spacing: bool
  • wrap_comments: bool
  • ignore: Vec<String>
  • contract_new_lines: bool
  • sort_imports: bool
  • pow_no_space: bool feat(fmt): option to remove spaces between number and exponent #4512

Pending TODOs

  • update README

@0xrusowsky 0xrusowsky moved this from In Progress to Ready For Review in Foundry Sep 2, 2025
@0xrusowsky 0xrusowsky marked this pull request as ready for review September 2, 2025 11:58
@0xrusowsky 0xrusowsky requested a review from DaniPopes September 2, 2025 11:58
@0xrusowsky 0xrusowsky enabled auto-merge (squash) September 5, 2025 06:41
@0xrusowsky 0xrusowsky requested a review from DaniPopes September 5, 2025 06:42
@0xrusowsky 0xrusowsky disabled auto-merge September 5, 2025 12:35
@grandizzy grandizzy added this to the v1.4.0 milestone Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

bug(fmt): modifies argument list in the presence of forgefmt: disable-next-line feat(fmt): option to remove spaces between number and exponent
3 participants